package piece1.chapter5;

public class Problem5_14 {

    /**
     * @param args
     */
    public static void main(String[] args) {
	// TODO 自动生成的方法存根
	double num[] = new double[100000];
	long startTime = System.nanoTime();
	for (int i = 0; i < num.length; i++) {
	    num[i] = Math.random() * 10000;

	}
	long endTIme = System.nanoTime();
	System.out.println("赋值经过了" + (endTIme - startTime) + "ns");
	startTime = System.currentTimeMillis();
	bubbleSort(num);
	endTIme = System.currentTimeMillis();
	System.out.println("排序经过了" + (endTIme - startTime) + "ms");

    }

    static double[] bubbleSort(double num[]) {
	boolean changed = false;
	do {
	    changed = false;
	    for (int i = 0; i < num.length - 1; i++) {
		if (num[i] > num[i + 1]) {
		    double temp = num[i];
		    num[i] = num[i + 1];
		    num[i + 1] = temp;
		    changed = true;

		}
	    }
	} while (changed);
	for (int i = 0; i < num.length; i++) {

	    // System.out.println("num[" + i + "]  " + num[i]);
	}

	return num;
    }
}
